package org.example.music_manage_system.mapper;

import org.example.music_manage_system.pojo.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {
    //新增
    @Insert("insert into yl_music.category(category_name,category_alias,create_user,create_time,update_time) " +
            "values(#{categoryName},#{categoryAlias},#{createUser},#{createTime},#{updateTime})")
    void add(Category category);
    //查询所有
    @Select("select * from yl_music.category where create_user=#{userId}")
    List<Category> List(Integer userId);
    //分类{id}查询
    @Select("select * from yl_music.category where id=#{id}")
    Category findById(Integer id);
    //更新分类
    @Update("update yl_music.category set category_name=#{categoryName},category_alias=#{categoryAlias},update_time=#{updateTime} where id=#{id}")
    void update(Category category);
    //删除分类
    // 更新 music 表，解除与分类的关联
    @Update("UPDATE yl_music.music SET category_id = NULL WHERE category_id = #{id}")
    void unlinkMusicFromCategory(Integer id);

    // 删除分类
    @Delete("DELETE FROM yl_music.category WHERE id = #{id}")
    void delete(Integer id);

}